
class Tree(object):
    
    def __init__(self, root, subtrees=None):
        self.root = root
        if subtrees is None:
            self.subtrees = []
        else:
            self.subtrees = subtrees
        
    def __eq__(self, other):
        return type(self) == type(other) and \
               (self.root, self.subtrees) == (other.root, other.subtrees)    
    
    def __ne__(self, other):
        return not (self == other)
    
    def __hash__(self):
        return hash((self.root, tuple(self.subtrees)))
    
    def __repr__(self):
        if self.subtrees:
            subreprs = ", ".join(`x` for x in self.subtrees)
            return "%r{%s}" % (self.root, subreprs)
        else:
            return `self.root`



# @deprecated: clients should use adt.tree.walk.RichTreeWalk instead
from walk import RichTreeWalk as Walk
Visitor = Walk.Visitor

